import numpy as np
import pandas as pd
import lightgbm as lgb
import sklearn.metrics as metrics

print('Stage1: load data')
# 说明
# 1. 这个路径名写法是Linux系统的，如果是windows系统，请修改为对应的格式
# 2. 这个文件只是简单地将所有时间序列点输入进去了，并没有做数据处理，大家可以自己尝试
X_train = np.load('./train/10type_sort_train_data_8192.npy')
y_train = np.load('./train/10type_sort_train_label_8192.npy')
X_test = np.load('./val/10type_sort_eval_data_8192.npy')
y_test = np.load('./val/10type_sort_eval_label_8192.npy')

test = np.load('./test/10type_sort_test_data_8192.npy')

params = {
    'boosting_type': 'gbdt',
    'objective': 'multiclass',
    'num_class': 10,
    'metric': 'multi_error',
    'num_leaves': 120,
    'min_data_in_leaf': 100,
    'learning_rate': 0.06,
    'feature_fraction': 0.8,
    'bagging_fraction': 0.8,
    'bagging_freq': 5,
    'lambda_l1': 0.4,
    'lambda_l2': 0.5,
    'min_gain_to_split': 0.2,
    'verbose': -1,
}

trn_data = lgb.Dataset(X_train, y_train)
val_data = lgb.Dataset(X_test, y_test)

print('Stage2: model training...')
clf = lgb.train(params,
                trn_data,
                num_boost_round = 1,
                valid_sets = [trn_data,val_data],
                verbose_eval = 10,
                early_stopping_rounds = 2)

print('Stage3: model score...')
y_prob = clf.predict(X_test, num_iteration=clf.best_iteration)
ans = [list(x).index(max(x)) for x in y_prob]


print("AUC score: {:<8.5f}".format(metrics.accuracy_score(ans, y_test)))

print('Stage4: make submmit...')
y_prob = clf.predict(test, num_iteration=clf.best_iteration)
ans = [list(x).index(max(x)) for x in y_prob]
pd.DataFrame({'Id':range(len(ans)), 'Category':ans}).to_csv('lgb_solution.csv', index=False)

